package emergency.activity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;

import com.xkh.xkh.MyApplication;
import com.xkh.xkh.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.List;

import emergency.adapter.DBEmergencyAdapter;
import emergency.adapter.EmergencyshowAdapter;
import managers.UIHandler;
import model.Emergency;

/**
 * Created by Administrator on 2016/4/6.
 */
public class EmergencyShow extends UIHandler.BaseActivity {

    List<Emergency> emergencys = new ArrayList<Emergency>();
    PullToRefreshListView pullToRefreshListView;
    ListView lv_refresh;

    EmergencyshowAdapter emergencyshowAdapter = new EmergencyshowAdapter();
    {
        emergencyshowAdapter.setEmergencys(emergencys);
    }

    DBEmergencyAdapter dbEmergencyAdapter  = new DBEmergencyAdapter();
    {
        dbEmergencyAdapter.setEmergencys(emergencys);
    }




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_emergencyshow);
        initview();
        initdata();
    }

    private void initdata() {
        dbEmergencyAdapter.init();
        emergencyshowAdapter.notifyDataSetChanged();
    }

    private void initview() {
        pullToRefreshListView = (PullToRefreshListView) findViewById(R.id.id_refreshlistview);
        pullToRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
        lv_refresh = pullToRefreshListView.getRefreshableView();
        lv_refresh.setAdapter(emergencyshowAdapter);
        lv_refresh.setDividerHeight((int)getResources().getDimension(R.dimen.y10));

        pullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                pullToRefreshListView.onRefreshComplete();
                int size = dbEmergencyAdapter.getOld();
                if (size == 0)
                {
                    Toast.makeText(MyApplication.share(),"没有更多了",Toast.LENGTH_SHORT).show();
                }
                emergencyshowAdapter.notifyDataSetChanged();
            }
        });
    }
}
